var year = new Date().getFullYear();//获取当前年份
var month = new Date().getMonth()+1;//获取当前月份
var thisdate = new Date().getDate();//获取当前日期
//noinspection JSValidateTypes
document.querySelector("#year").innerHTML = year;
//noinspection JSValidateTypes
document.querySelector("#month").innerHTML = month;
var days = 0;
function runnian(y){
    return !!(y % 400 === 0 || (y % 4 === 0 && y % 100 !== 0));
}
//1980到2018年之间一共有多少天
for (var i = 1980;i < year;i++){
    if (runnian(i)){
        days += 366;
    }else {
        days += 365;
    }
}
days += 2;
//这个月的上几月一共多少天
for (var y = 1;y < month;y++){
    switch (y){
        case 1:
            days += 31;
            break;
        case 2:
            if (runnian(year)){
                days += 29;
                break;
            }else {
                days += 28;
                break;
            }
        case 3:
            days += 31;
            break;
        case 4:
            days += 30;
            break;
        case 5:
            days += 31;
            break;
        case 6:
            days += 30;
            break;
        case 7:
            days += 31;
            break;
        case 8:
            days += 31;
            break;
        case 9:
            days += 30;
            break;
        case 10:
            days += 31;
            break;
        case 11:
            days += 30;
            break;
        case 12:
            days += 31;
            break;
    }
}
//mouth的上个月有多少天
var prevday = 0;
if (month == 1){
    prevday += 31;
}else {
    switch (month - 1) {
        case 1:
            prevday += 31;
            break;
        case 2:
            if (runnian(year)) {
                prevday += 29;
                break;
            } else {
                prevday += 28;
                break;
            }
        case 3:
            prevday += 31;
            break;
        case 4:
            prevday += 30;
            break;
        case 5:
            prevday += 31;
            break;
        case 6:
            prevday += 30;
            break;
        case 7:
            prevday += 31;
            break;
        case 8:
            prevday += 31;
            break;
        case 9:
            prevday += 30;
            break;
        case 10:
            prevday += 31;
            break;
        case 11:
            prevday += 30;
            break;
        case 12:
            prevday += 31;
            break;
    }
}

//mouth这个月有多少天
var day = 0;
switch (month){
    case 1:
        day += 31;
        break;
    case 2:
        if (runnian(year)){
            day += 29;
            break;
        }else {
            day += 28;
            break;
        }
    case 3:
        day += 31;
        break;
    case 4:
        day += 30;
        break;
    case 5:
        day += 31;
        break;
    case 6:
        day += 30;
        break;
    case 7:
        day += 31;
        break;
    case 8:
        day += 31;
        break;
    case 9:
        day += 30;
        break;
    case 10:
        day += 31;
        break;
    case 11:
        day += 30;
        break;
    case 12:
        day += 31;
        break;
}
start = days % 7;//算出空几个位
if(start == 0){//如果start等于0，让他加7
    start += 7;
}
num = 42;//一页一共有42个空位
var nextmonth = num - start - day;//算出下个月有多少天
var date = document.querySelector(".date");//算出下个月有多少天
var j = prevday;
for (j = prevday - start +1;j <= prevday;j++){
    date.innerHTML += "<span class='a'>"+j+"</span>"
}
for (var k = 1;k <= day;k++){
    if (k == thisdate){
        date.innerHTML += "<span class='today'>"+k+"</span>"
    }else {
        date.innerHTML += "<span>"+k+"</span>"
    }
}
for (var l = 1;l <= nextmonth;l++){
     date.innerHTML += "<span class='a'>"+l+"</span>"
}













